package com.crm.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.crm.entity.Dynamicmessages;
import com.crm.repository.MessageRepository;
import com.crm.service.impl.MessageServiceImpl;

@RestController
@RequestMapping("/message")
public class MessageController {

	@Autowired
	private MessageServiceImpl messageService;
	@Autowired
	private MessageRepository messageRepository;
	@GetMapping
	public Object getMessage(String receiveId) {
		System.out.println("receiveId:"+receiveId);
		Map<String , Object> map=new HashMap<String, Object>();
		map.put("code", 0);
		map.put("data", messageService.checkDyniMessage(receiveId));
		
		return map;
	}
	
	@PutMapping
	public Object updateMessage(Dynamicmessages message) {
		Optional<Dynamicmessages> m = messageRepository.findById(message.getDid());//查出原先值
		
		Dynamicmessages message1 = m.get();
		message1.setBackContent(message.getBackContent());
		message1.setIsReply("1");
		return messageService.updateMessage(message1);
	}
}
